﻿using BackData;
using Domain;
using Domain.BOM;
using Domain.DTOs.Quality;
using Domain.RBAC;
using MediatR;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Team.API.Applocation.Command.Quality;

namespace Team.API.Controllers
{
    /// <summary>
    /// 质检的控制器
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class QualityController : ControllerBase
    {
        private readonly IMediator mediator;

        public QualityController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 创建质检
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<APIResult<int>> CreateQuality(CreateQualityCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取质检列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPaging<QualityListDto>> GetQualityList([FromQuery]GetQualityListCommand request)
        {
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取来源工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Workmodel>>> GetWork()
        {
            GetWorkCommand request=new GetWorkCommand();
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取生成物品
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Bomtable>>> GetBom()
        {
            GetBomCommand request=new GetBomCommand();
            return await mediator.Send(request);
        }
        /// <summary>
        /// 获取用户
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<List<Usermodel>>> GetUser()
        {
            GetUserCommand request=new GetUserCommand();
            return await mediator.Send(request);
        }

        /// <summary>
        /// 根据ID获取质检表数据（用于反填）
        /// </summary>
        /// <param name="request">包含质检工单ID的请求</param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIResult<QualityListDto>> FindQuality([FromQuery]FindQualityCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 获取质检报工列表
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<APIPaging<QualityReportDto>> GetQualityReportList([FromQuery]GetQualityReportListCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 删除质检工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpDelete]
        public async Task<APIResult<int>> DeleteQuality([FromQuery]DeleteQualityCommand request)
        {
            return await mediator.Send(request);
        }

        /// <summary>
        /// 编辑质检工单
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        [HttpPut]
        public async Task<APIResult<int>> UpdateQuality(UpdateQualityCommand request)
        {
            return await mediator.Send(request);
        }
    }
}
